package com.lw.biz.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lw.base.client.result.BaseResult;
import com.lw.biz.client.model.BizCategoryModel;
import com.lw.biz.client.service.IBizCategoryService;
import com.lw.biz.dal.dao.BizCategoryDao;
import com.lw.biz.dal.entity.BizCategory;

@Service("iBizCategoryService")
public class IBizCategoryServiceImpl implements IBizCategoryService {

	@Autowired
	private BizCategoryDao bizCategoryDao;
	
	public BaseResult<List<BizCategoryModel>> getAllCategory() {
		try {
			List<BizCategory> dbList = bizCategoryDao.selectAll();
			List<BizCategoryModel> reList = new ArrayList<BizCategoryModel>();
			for(BizCategory bizCategory : dbList){
				BizCategoryModel bizCategoryModel = new BizCategoryModel();
				BeanUtils.copyProperties(bizCategory, bizCategoryModel);
				reList.add(bizCategoryModel);
			}
			return new BaseResult<List<BizCategoryModel>>(reList);
		} catch (Exception e) {
			e.printStackTrace();
			return new BaseResult<List<BizCategoryModel>>(null,BaseResult.FAIL,false,e.getMessage());
		}
	}
}
